package com.victor9ac;

import java.net.UnknownHostException;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class MongoDB {

	private static MongoDB mongoDB;
	
	private MongoDB(){
	}
	
	public static MongoDB getInstance(){
		if (mongoDB == null){
			mongoDB = new MongoDB();
			return mongoDB;
		}else{
			return mongoDB;
		}
	}
	
	
	
	
	public String getOneAtributteA() throws UnknownHostException {
		MongoClient mongoClient = new MongoClient(new ServerAddress("localhost",27017));
		
		DB database = mongoClient.getDB("mentidero");
		DBCollection collection = database.getCollection("cai");
		
		DBObject dbObject = collection.findOne();
		
		;
		
		
		return ((Double)dbObject.get("a")).toString();
	}
	
	
	public String getOneObject() throws UnknownHostException {
		MongoClient mongoClient = new MongoClient(new ServerAddress("localhost",27017));
		
		DB database = mongoClient.getDB("mentidero");
		DBCollection collection = database.getCollection("cai");
		
		DBObject dbObject = collection.findOne();
		
		;
		
		
		return ((Double)dbObject.get("a")).toString();
	}
	
}
